﻿Imports System.Net
Imports System.Threading
Imports System.IO

Public Class about
    Dim returnValue As String
    Dim channel As String
    Dim debugC = 0
    Private Sub about_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        channel = "stable"
        Me.Show()
        Label1.Location = New Point(Me.Width \ 2 - Label1.Width \ 2, Label1.Top)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        On Error Resume Next
        Dim listArray(1) As String
        If Button1.Text = "Check for Updates" Then
            Updatecheck()
        End If

        If Button1.Text = "Download New Update" Then
            'Continue down the code
        Else
            Exit Sub
        End If
        If channel = "beta" Then     ' note from 2015: This is old stuff from when I was deving and had a beta and stable branch. If you want to bring that back, go ahead. 

            '    If System.IO.File.Exists("betaup100.exe") Then
            '        Process.Start("betaup100.exe")
            '        End
            '    Else
            '        My.Computer.Network.DownloadFile("https://drsshm.googlecode.com/files/betaup110", "betaup110.exe")
            '        If System.IO.File.Exists("betaup100.exe") Then
            '            MsgBox("The updater has downloaded. Press 'OK' to start. You may see a black screen appear briefly.")
            '            Process.Start("betaup100.exe")
            '            End
            '        End If
            '    End If
            'Else

        End If
        If channel = "stable" Then
            If System.IO.File.Exists("updater.exe") Then
                Process.Start("updater.exe")
                End
            Else
                'My.Computer.Network.DownloadFile("http://ubuntuone.com/4MF7i7rrNlaJoQaQCHig9b", "updater.exe")

            End If
        End If
        If Err.Number <> 0 Then
            MsgBox("The update did not work:" & vbCrLf & Err.Description & vbCrLf & Err.Source, vbOKOnly - vbExclamation, +"This might mean that you are not connected to the internet, or Mr. Slone hates you.")
        Else
        End If
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Dim url As String = "https://code.google.com/p/drsshm"
        Process.Start(url)
    End Sub

    Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles Label1.Click

    End Sub
    ' I used Ubuntu One because it is the only the host (after Google code stopped) that provides a form of 'direct linking'. If the option is 
    ' presented, switch to something else. 

    '2015 Update: If you intend on resurecting the updater, uncomment all the code below, and change the update server. More info on how this works is at drsshm.googlecode.com
    Private Sub Updatecheck()
        MsgBox("The DRSS Homework Manager was developed by Matthew Kowal, a member of the class of 2014. This version was the last update." +
               vbNewLine + "If you would like to continue the development, you can get the source code (Visual Basic) from drsshm.googlecode.com, and/or contact kowal@null.net." +
               vbNewLine + "Thanks for using this program!")

        'Dim upArray(1) As String
        'If My.Computer.Network.IsAvailable Then
        '    'Dim instance As WebClient = New WebClient                    ' This is the old method, for reference. 

        '    'Dim address As String = "https://drsshm.googlecode.com/files/rv.kuf"
        '    'returnValue = instance.DownloadString(address)


        '    If File.Exists("update.kwl") Then
        '        File.Delete("update.kwl")
        '        My.Computer.Network.DownloadFile("http://ubuntuone.com/2rnaU9iu4SRJ58BI4Gr7FN", "update.kwl")
        '    Else
        '        My.Computer.Network.DownloadFile("http://ubuntuone.com/2rnaU9iu4SRJ58BI4Gr7FN", "update.kwl")
        '    End If

        '    upArray = File.ReadAllLines("update.kwl")


        '    If upArray(0) = "1.2.0.0" Then
        '        Label3.Text = "No new updates"
        '        Button1.Text = "Check for Updates"
        '        Label3.Location = New Point(Me.Width \ 2 - Label3.Width \ 2, Label3.Top)
        '    Else
        '        Label3.Text = "New update: " + upArray(0)
        '        Label3.Location = New Point(Me.Width \ 2 - Label3.Width \ 2, Label3.Top)
        '        Button1.Text = "Download New Update"
        '    End If

        'Else
        '    MsgBox("You are not connected to the Internet, which makes checking for updates somewhat difficult.")
        'End If

        'If upArray(0) = "" Then
        '    Label3.Text = "Connection error!"
        '    Label3.Location = New Point(Me.Width \ 2 - Label3.Width \ 2, Label3.Top)
        '    Button1.Text = "Check for Updates"
        'End If
        'If upArray(0).Chars(0) = "<" Then
        '    Label3.Text = "Login to network!"
        '    Label3.Location = New Point(Me.Width \ 2 - Label3.Width \ 2, Label3.Top)
        '    Button1.Text = "Check for Updates"
        'End If
    End Sub

    Private Sub ThreadProcSafe()    'I don't remember what this does...
        Throw New NotImplementedException
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs)

    End Sub
    Private Sub debugOn() Handles Me.Click   'I don't remember if this is important or not. 
        debugC = debugC + 1
        If debugTimer.Enabled = True Then
        Else
            debugTimer.Enabled = True
            debugTimer.Start()
        End If
        If debugC = 5 Then
            Button1.Enabled = True
            Button1.Text() = "Check for Updates"

        End If
    End Sub

    Private Sub debugTimer_Tick(sender As Object, e As EventArgs) Handles debugTimer.Tick
        debugC = 0
    End Sub
End Class
'    This program is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.

'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with this program.  If not, see <http://www.gnu.org/licenses/>